package com.ljx.itbbs.server.mall.dao;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ljx.itbbs.server.mall.domain.entity.CouponRecordEntity;
import com.ljx.itbbs.server.mall.domain.enums.CouponUseEnum;
import com.ljx.itbbs.server.mall.mapper.CouponRecordMapper;
import org.springframework.stereotype.Service;

@Service
public class CouponRecordDao extends ServiceImpl<CouponRecordMapper, CouponRecordEntity> {

    public void useCoupon(Long couponId, Long userId) {
        lambdaUpdate().set(CouponRecordEntity::getIsUse, CouponUseEnum.USE.getType())
                .eq(CouponRecordEntity::getCouponId, couponId)
                .eq(CouponRecordEntity::getUserId, userId)
                .update();
    }

    public CouponRecordEntity getCouponRecord(Long userId, Long couponId) {
        return lambdaQuery().eq(CouponRecordEntity::getUserId, userId)
                .eq(CouponRecordEntity::getCouponId, couponId)
                .one();
    }
}
